//
//  ST_TIANPageSheetContainer.swift
//  btvideo
//
//  Created by Jason on 2021/9/9.
//  Copyright © 2021 JarvanZhang. All rights reserved.
//

import UIKit
//import Rswift

class ST_TIANPageSheetContainer: UIView {
    
    
    convenience init(arrowsOffsetX:CGFloat,childView:UIView) {
        
        self.init()
        
        self.addSubview(childView)
        
        childView.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(childView.frame.minX)
            make.top.equalToSuperview().offset(childView.frame.minY)
            make.size.equalTo(childView.size)
        }
        
        box_background_view.snp.makeConstraints { make in
            make.edges.equalTo(childView).inset(box_padding)
        }
        
        arrows_image_view.snp.makeConstraints { make in
            make.height.equalTo(8)
            make.width.equalTo(36/2.0)
            make.bottom.equalTo(childView.snp.top).offset(0)
            make.left.equalTo(childView).offset(arrowsOffsetX)
        }
        
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        self.backgroundColor = .clear
        
        self.addSubview(close)
        close.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        
        self.addSubview(box_background_view)
        self.addSubview(arrows_image_view)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    fileprivate lazy var close:UIButton = {
        let btn = UIButton.init(type: UIButton.ButtonType.custom)
        
        btn.backgroundColor = .clear
        btn.addTarget(self, action: #selector(close_handle), for: UIControl.Event.touchUpInside)
        return btn
    }()

    fileprivate lazy var box_background_view:UIImageView = {
        let v = UIImageView()
        v.contentMode = .scaleToFill
        v.image = ST_ImageUtils.imageName("page_sheet_background")
        return v
    }()
    
    let paddingValue = -20.cgFloat
    
    fileprivate lazy var box_padding:UIEdgeInsets = .init(top: paddingValue, left: paddingValue, bottom: paddingValue, right: paddingValue)
    
    fileprivate lazy var arrows_image_view:UIImageView = {
        let v = UIImageView()
        v.image = ST_ImageUtils.imageName("arrows_top_icon")
        //v.cornerRadius = 5
        return v
    }()
}

extension ST_TIANPageSheetContainer{
    
    @objc fileprivate func close_handle(){
        
        
        UIView.animate(withDuration: 0.25) {
            self.alpha = 0
        } completion: { _ in
            self.removeFromSuperview()
        }
    }
}
